/*
 * Copyright (C) 2008-2012  Paulo Cesar Pereira de Andrade.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors:
 *	Paulo Cesar Pereira de Andrade
 */

#ifndef _ehash_h
#define _ehash_h

#include "etypes.h"

#define ehash_p(object)		(etype(object) == t_hash)

#define enew_entry(pointer, name, value)				\
    enew_entry_base(pointer, name, value, t_entry, sizeof(eentry_t))

/*
 * Types
 */
struct eentry {
    eentry_t		 *next;
    eobject_t		  value;
    eobject_t		  name;
    eword_t		  key;
};

struct ehash {
    /* evector_t */
    eentry_t		**entries;
    eword_t		  size;			/* size of entries vector */
    eword_t		  count;		/* number of entries */
};

/*
 * Prototypes
 */
extern void
init_hash(void);

extern void
finish_hash(void);

extern void
enew_hash(eobject_t *pointer, eword_t size);

extern void
enew_entry_base(eobject_t *pointer, eobject_t name, eobject_t value,
		etype_t type, eword_t length);

extern void
eput_hash(ehash_t *hash, eentry_t *entry);

extern eentry_t *
eget_hash(ehash_t *hash, eobject_t name);

extern eentry_t *
eget_hash_string(ehash_t *hash, euint8_t *name, eint32_t length);

extern void
erem_hash(ehash_t *hash, eentry_t *entry);

extern void
eclr_hash(ehash_t *hash);

#endif /* _ehash_t */
